<?php

namespace Admin\Model\DAO;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Adapter\Adapter;

class CiculationPolicyTable extends AbstractTableGateway {

    protected $table;
    protected $adapter;
    protected $resultSetPrototype;

    public function __construct(Adapter $adapter) {
        $this->table = 'lib_ciculationpolicies';
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
    }

    public function fetchAll() {
        $sql = new Sql($this->adapter);
        $select = $sql->select();
        $select->from($this->table);
        $statement = $sql->prepareStatementForSqlObject($select);
        $result = $statement->execute();
        $resultSet = clone $this->resultSetPrototype;
        $resultSet->initialize($result);
        $resultSet->buffer();
        $resultSet->next();
        return $resultSet;
    }

    public function getCiculationPolicy($policyID) {
        try {
            $sql = new Sql($this->adapter);
            $select = $sql->select();
            $select->from(array('c' => 'lib_ciculationpolicies'));
            $where = new Where();
            $where->equalTo('c.policyID', $policyID);
            $select->where($where);
            $statement = $sql->prepareStatementForSqlObject($select);
            $result = $statement->execute();
            $row = $result->current();
            return $row;
        } catch (Exception $e) {
            throw new \Exception("Could not excuteQuery getInfoPolicy()");
        }
    }
    public function updatePolicy($data, $policyID) {
        $this->update($data,array('policyID' => $policyID));
    }
}

?>
